package com.sjl.utils;

import com.alibaba.fastjson.JSONObject;
import com.sjl.http.HttpClientUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取地址类
 * 
 * @author ruoyi
 */
public class AddressUtils
{


    public static final String IP_URL = "http://ip.taobao.com/service/getIpInfo.php";

    public static String getRealAddressByIP(String ip)
    {
        String address = "";
        try
        {
            Map<String, String> param = new HashMap<>(1);
            param.put("ip",ip);
            address = HttpClientUtil.doPost(IP_URL, param);
            JSONObject json = JSONObject.parseObject(address);
            JSONObject object = json.getObject("data", JSONObject.class);
            String region = object.getString("region");
            String city = object.getString("city");
            address = region + " " + city;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return address;
    }
}
